<!--  -->
<template>
  <div class="info_wrap" v-loading="isLoading" element-loading-text="加载中...">
    <div class="info">
      <div class="header">
        <div class="cover">
          <img :src="profile.avatarUrl" preview="profile.avatarUrl" alt="" />
          <!-- <el-image
            :src="profile.avatarUrl"
            :preview-src-list="[profile.avatarUrl]"
            ></el-image> -->
        </div>
        <div class="title_wrap">
          <div class="title">
            <div class="name_info">
              <div class="name">{{ profile.nickname }}</div>
              <span class="lv"
                >L V {{ userinfo.level ? userinfo.level : "0" }}</span
              >
              <span v-if="profile.gender !== 0" class="sex"
                >姓别 : {{ profile.gender === 1 ? "男" : "女" }}</span
              >
            </div>
            <div v-if="userId != profile.userId" class="tag_info">
              <div
                @click="follow(profile.userId, 2)"
                v-show="profile.followed && profile.followMe"
                class="follow"
              >
                互相关注
              </div>
              <div
                @click="follow(profile.userId, 2)"
                v-show="profile.followed && profile.followMe == false"
                class="follow"
              >
                已关注
              </div>
              <div
                @click="follow(profile.userId, 1)"
                v-show="profile.followed == false"
                class="follow"
              >
                关注
              </div>
            </div>
            <div v-else class="tag_info complie">
              <div
                @click="toComplie(profile.userId)"
                class="follow el-icon-edit"
              >
                编辑个人信息
              </div>
            </div>
          </div>
          <div class="content">
            <div class="number">
              <div @click="toEvent(profile.userId)" class="num_wrap">
                <div class="num">{{ profile.eventCount }}</div>
                <div class="cri">动态</div>
              </div>
              <div @click="toFollows(profile.userId)" class="num_wrap">
                <div class="num">{{ profile.follows }}</div>
                <div class="cri">关注</div>
              </div>
              <div @click="toFolloweds(profile.userId)" class="num_wrap">
                <div class="num">{{ profile.followeds }}</div>
                <div class="cri">粉丝</div>
              </div>
            </div>
            <div v-if="province" class="address">
              所在地区 : {{ province }} {{ city }}
            </div>
            <div class="social">社交网络 : 微博</div>
            <div class="introduce">个人介绍 : {{ profile.signature }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="song_list">
      <div v-if="createList.length > 0" class="created_list">
        <div class="title">
          {{ userId == profile.userId ? "我" : profile.nickname }}创建的歌单（{{
            createList.length
          }}）
        </div>
        <div class="list_wrap">
          <div
            class="item_wrap"
            v-for="(item, index) in createList"
            :key="index"
          >
            <div class="item">
              <div @click="toDetail(item.id)" class="cover">
                <el-image
                  :src="item.coverImgUrl"
                  fit="cover"></el-image>
                <span class="count"
                  ><span class="iconfont el-icon-caret-right"></span
                  >{{
                    item.playCount > 100000
                      ? Math.floor(item.playCount / 100000) + "万"
                      : item.playCount
                  }}</span
                >
              </div>
              <div class="name">{{ item.name }}</div>
              <div class="song_count">{{ item.trackCount }}首</div>
            </div>
          </div>
        </div>
      </div>

      <div v-if="collectList.length > 0" class="created_list">
        <div class="title">
          {{ userId == profile.userId ? "我" : profile.nickname }}收藏的歌单（{{
            collectList.length
          }}）
        </div>
        <div class="list_wrap">
          <div
            class="item_wrap"
            v-for="(item, index) in collectList"
            :key="index"
          >
            <div class="item">
              <div @click="toDetail(item.id)" class="cover">
                <el-image :src="item.coverImgUrl" fit="cover"></el-image>
                <!-- <img :src="item.coverImgUrl" alt="" /> -->
                <span class="count"
                  ><span class="iconfont el-icon-caret-right"></span
                  >{{
                    item.playCount > 100000
                      ? Math.floor(item.playCount / 100000) + "万"
                      : item.playCount
                  }}</span
                >
              </div>
              <div class="name">{{ item.name }}</div>
              <div class="song_count">{{ item.trackCount }}首</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { provinceAndCityData, CodeToText } from "element-china-area-data";
import { getUserInfo, getUserPrivatePlayList, Follow } from "util/login";
export default {
  name: "userinfo",
  data() {
    return {
      currentId: this.$route.params.id,
      userinfo: {},
      profile: {},
      createList: [],
      collectList: [],
      province: "",
      city: "",
    };
  },
  created() {
    this.getUserInfo();
    this.getUserPrivatePlayList();
  },
  watch: {
    $route(to, from) {
      console.log(to, from, "5555555");
    },
  },
  computed: {
    ...mapGetters("userInfo", [
      //登录状态
      "loginStatus",
      "userId",
    ]),
    ...mapGetters("musicPlay", ["isLoading"]),
  },
  methods: {
    //获取用户信息
    async getUserInfo() {
      this.$store.dispatch("musicPlay/changeIsLoading", true);
      let { data } = await getUserInfo(this.$route.params.id);
      // console.log(data)
      this.userinfo = data;
      this.profile = data.profile;
      this.province = CodeToText[this.profile.province.toString()];
      this.city = CodeToText[this.profile.city.toString()];
    },
    //获取用户歌单
    async getUserPrivatePlayList() {
      let {
        data: { playlist },
      } = await getUserPrivatePlayList(this.$route.params.id);
      // console.log(playlist)
      playlist.forEach((item) => {
        if (item.creator.nickname === this.profile.nickname) {
          this.createList.push(item);
        } else {
          this.collectList.push(item);
        }
      });
      // console.log(this.collectList)
      // console.log(this.createList)
      this.$store.dispatch("musicPlay/changeIsLoading", false);
    },
    toDetail(id) {
      this.$store.dispatch("musicPlay/saveSongListId", id);
      this.$router.push("/songListPage/" + id);
    },
    //去关注界面
    toFollows(id) {
      this.$router.push("/userFollows/" + id);
    },
    //去粉丝界面
    toFolloweds(id) {
      this.$router.push("/userFolloweds/" + id);
    },
    // 关注功能
    async follow(id, type) {
      if (this.loginStatus == "false") {
        this.$message("请登录后使用此功能哦！");
        return;
      }
      let { data } = await Follow(id, type);
      if (data.code == "200" && type === 1) {
        this.$message(data.followContent);
        this.profile.followed = true;
      } else {
        this.$message("取消关注成功");
        this.profile.followed = false;
      }
    },
    //去编辑资料界面
    toComplie(id) {
      this.$router.push("/userEdit/id" + id);
    },
    //去动态界面
    toEvent(id) {
      this.$router.push("/userevent/" + id);
    },
  },
};
</script>

<style scoped lang='less'>
.info {
  padding: 25px 30px;
  .header {
    display: flex;
    .cover {
      width: 11%;
      height: 11%;
      // width: 180px;
      // height: 180px;
      border-radius: 50%;
      .el-image {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
    .title_wrap {
      margin-left: 30px;
      .title {
        width: 66vw;
        padding-bottom: 15px;
        border-bottom: 1px solid #e5e5e5;
        display: flex;
        justify-content: space-between;
        .name_info {
          .name {
            color: #450752;
            font-size: 22px;
            font-weight: 600;
          }
          .lv {
            display: inline-block;
            margin-top: 10px;
            font-weight: 600;
            // background-color: #f0f0f0;
            font-size: 16px;
            width: 55px;
            text-align: center;
            color: #450752;
          }
          .sex {
            margin-left: 10px;
            font-size: 16px;
            font-weight: 600;
            color: #450752;
          }
        }
        .tag_info {
          cursor: pointer;
          display: flex;
          justify-content: center;
          align-items: center;
          .follow {
            border: 1px solid rgb(202, 194, 194);
            border-radius: 20px;
            padding: 5px 15px;
            font-size: 15px;
            font-weight: 600;
          }
          .follow:hover {
            background-color: #eee;
          }
          .el-icon-edit {
            color: rgba(0, 0, 0, 0.829);
            padding: 8px 20px;
          }
        }
      }

      .content {
        font-weight: 600;
        .number {
          display: flex;
          margin-top: 20px;
          position: relative;
          left: -26px;
          .num_wrap:nth-child(3) {
            border-right: none;
          }
          .num_wrap {
            cursor: pointer;
            width: 80px;
            text-align: center;
            border-right: solid 1px #ddd;
            .num {
              font-size: 18px;
              font-weight: 600;
            }
            .cri {
              font-size: 12px;
              color: #676767;
            }
          }
        }
        .address {
          margin-top: 10px;
          color: #676767;
          font-size: 13px;
        }
        .social {
          margin-top: 10px;

          color: #676767;
          font-size: 13px;
        }
        .introduce {
          margin-top: 10px;

          color: #676767;
          font-size: 13px;
        }
      }
    }
  }
}
.song_list {
  width: 100%;
  .title {
    font-weight: 600;
    margin-bottom: 20px;
    font-size: 20px;
    margin-left: 2.475rem;
  }
}
// [class*="el-col-"] {
//   display: inline-block;
//   float: none;
// }
.created_list {
  .list_wrap {
    display: flex;
    flex-wrap: wrap;
    .item_wrap {
      display: flex;
      .item {
        // width: 12.5rem;
        height: 15.625rem;
        position: relative;
        margin-bottom: 5px;
        margin-left: 2.5rem;
        .cover {
          width: 11.25rem;
          height: 11.25rem;
          // height: 194px;
          .el-image {
            width: 100%;
            height: 100%;
            border-radius: 6px;
            box-shadow: 0px 2px 12px 0 rgba(0, 0, 0, 0.2);
          }
          img {
            transition: 2s;
          }
        }
        .count {
          position: absolute;
          top: 2%;
          right: 6%;
          font-size: 10px;
          color: #fff;
          .iconfont {
            font-size: 14px;
            margin-right: 3px;
          }
        }
        .name {
          width: 200px;
          color: #373737;
          font-size: 14px;
          line-height: 35px;
          font-weight: 600;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .song_count {
          font-size: 12px;
          color: #9f9f9f;
        }
      }
    }
  }
}
</style>